package net.huashitong.ssydt.provider.sys.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.huashitong.ssydt.PaginationResult;
import net.huashitong.ssydt.provider.sys.service.SsSysBasService;
import net.huashitong.ssydt.provider.web.model.Result;
import net.huashitong.ssydt.provider.web.utils.ResultUtils;
import net.huashitong.ssydt.sys.entity.SsSysBas;
import net.huashitong.ssydt.sys.entity.vo.SsSysBasInVO;
import net.huashitong.ssydt.sys.entity.vo.SsSysBasQueryInVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;

/**
 * @author hemj
 * @version 2017/8/23
 */
@Api(value = "/sys/bas", tags = {"系统参数表管理（后台）"})
@RestController
@RequestMapping("/sys/bas")
public class SsSysBasController {
	private SsSysBasService ssSysBasService;

	@Autowired
	public SsSysBasController(SsSysBasService ssSysBasService) {
		this.ssSysBasService = ssSysBasService;
	}

	@ApiOperation(value = "获取参数列表", notes = "获取参数列表")
	@GetMapping("/{basType}")
	public Result<ArrayList<SsSysBas>> basList(@PathVariable String basType) {
		return ResultUtils.getSuccessResultList(ssSysBasService.queryNotTypeByBasType(basType));
	}

	@ApiOperation(value = "系统参数表查询", notes = "系统参数表分页查询")
	@GetMapping
	public Result<PaginationResult<SsSysBas>> paginationQuery(@ModelAttribute SsSysBasQueryInVO ssSysBasQueryInVO) {
		return ResultUtils.getSuccessResults(ssSysBasService.paginationQuery(ssSysBasQueryInVO));
	}

	@ApiOperation(value = "新增系统参数", notes = "新增系统参数")
	@PostMapping
	public Result<String> post(@Valid SsSysBasInVO ssSysBasInVO) {
		SsSysBas ssSysBas = new SsSysBas();
		BeanUtils.copyProperties(ssSysBasInVO, ssSysBas);
		ssSysBasService.addSysBas(ssSysBas);
		return ResultUtils.getSuccessResults();
	}

	@ApiOperation(value = "修改系统参数", notes = "修改系统参数")
	@PutMapping("/{basId}")
	public Result<String> put(@PathVariable Long basId, @Valid SsSysBasInVO ssSysBasInVO) {
		SsSysBas ssSysBas = new SsSysBas();
		BeanUtils.copyProperties(ssSysBasInVO, ssSysBas);
		ssSysBas.setId(basId);
		ssSysBasService.updateSysBas(ssSysBas);
		return ResultUtils.getSuccessResults();
	}

	@ApiOperation(value = "删除系统参数", notes = "删除系统参数")
	@DeleteMapping("/{basId}")
	public Result<String> delete(@PathVariable Long basId) {
		ssSysBasService.deleteSysBas(basId);
		return ResultUtils.getSuccessResults();
	}
}
